package offerv1;

public class Offer63 {

    //1.暴力解 双重循环
    //2.不断更新最低点
    public int maxProfit(int[] prices) {
        int n = prices.length, minPrice = Integer.MAX_VALUE, maxProfit = 0;
        for (int price : prices) {
            if (price < minPrice) {
                minPrice = price;
            } else if (price - minPrice > maxProfit) {
                maxProfit = price - minPrice;
            }
        }

        return maxProfit;
    }
}
